﻿@{
    ViewData["Title"] = "导航";
}

@model Mango.Web.ViewModels.NavigationViewModel
    <div class="row">
        
        <div class="col-lg-12" id="showNavigationMain">
            @foreach (var item in Model.ClassifyListData)
            {
                <div class="my-2 p-1 bg-white rounded box-shadow" data-id="@item.CId">
                    <h5 class="border-bottom border-gray pb-2 mb-0">@item.ClassifyName</h5>
                    <div class="row text" style="padding-top:5px;" id="showNavigationList@(item.CId)">
                        
                       
                    </div>
                </div>
            }
            
        </div>
    </div>
@section Scripts{
    <script type="text/javascript">
        $(window).ready(function () {
            $.ajax({
                type: 'post',
                url: '/navigation/LoadList',
                success: function (result) {
                    var d = JSON.parse(result);
                    //获取导航分类对象
                    var nc = $("#showNavigationMain").children();
                    $.each(d, function (i) {
                        $.each(nc, function (j) {
                            if (d[i].CId == $(nc[j]).attr('data-id')) { 
                                //把数据插入到相应的分类下
                                $("#showNavigationList" + d[i].CId).append(CreateHtml(d[i]));
                            }
                        });
                    });
                }
            });
        });
        function CreateHtml(d) { 
            var html = '<div class="col-lg-3">';
                            html+='<div class="card">';
                                html+='<div class="card-body">';
                                    html+='<h6 class="card-title">' + d.NavigationName +'</h6>';
                                    html+='<p class="card-text" style="font-size:12px;">'+d.Remark+'</p>';
                                    html+='<a href="javascript:UpdateCount(' + d.NavigationId + ',\'' + d.NavigationUrl+'\');" class="btn btn-primary">点击浏览<span class="badge badge-light" style="margin-left:3px;">'+d.ClickCount+'</span></a>';
                                html+='</div>';
                            html+='</div>';
                        html+='</div>';
            return html;
        }
        function UpdateCount(id,url) {
            $.ajax({
                type: 'post',
                url: '/navigation/UpdateClickCount',
                data: 'navigationId=' + id,
                success: function (res) { 
                    if (res) {
                        console.log("UpdateCount:" + res);
                    }
                }
            });
            window.open(url,"51coreLink");
        }
    </script>
}
